<?php

/**
 * This is the model class for table "{{species}}".
 *
 * The followings are the available columns in table '{{species}}':
 * @property string $id
 * @property string $ac_fao
 * @property string $medits_code
 * @property string $scientific_name
 * @property string $common_name
 * @property string $faunistic_category
 * @property string $family
 * @property string $unit_measurement
 * @property string $biomar_name
 * @property integer $visible
 *
 * The followings are the available model relations:
 * @property Yield[] $yields
 */
class Species extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Species the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{species}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ac_fao, medits_code, scientific_name, common_name, faunistic_category, family, unit_measurement, biomar_name, visible', 'required'),
			array('visible', 'numerical', 'integerOnly'=>true),
			array('ac_fao, faunistic_category', 'length', 'max'=>3),
			array('medits_code', 'length', 'max'=>8),
			array('scientific_name, common_name, biomar_name', 'length', 'max'=>40),
			array('family', 'length', 'max'=>20),
			array('unit_measurement', 'length', 'max'=>2),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, ac_fao, medits_code, scientific_name, common_name, faunistic_category, family, unit_measurement, biomar_name, visible', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'yields' => array(self::HAS_MANY, 'Yield', 'species_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'ac_fao' => 'Ac Fao',
			'medits_code' => 'Medits Code',
			'scientific_name' => 'Scientific Name',
			'common_name' => 'Common Name',
			'faunistic_category' => 'Faunistic Category',
			'family' => 'Family',
			'unit_measurement' => 'Unit Measurement',
			'biomar_name' => 'Biomar Name',
			'visible' => 'Visible',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('ac_fao',$this->ac_fao,true);
		$criteria->compare('medits_code',$this->medits_code,true);
		$criteria->compare('scientific_name',$this->scientific_name,true);
		$criteria->compare('common_name',$this->common_name,true);
		$criteria->compare('faunistic_category',$this->faunistic_category,true);
		$criteria->compare('family',$this->family,true);
		$criteria->compare('unit_measurement',$this->unit_measurement,true);
		$criteria->compare('biomar_name',$this->biomar_name,true);
		$criteria->compare('visible',$this->visible);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}